package com.sgzn.sgpay.service.tcp.model.terminal.request;

import com.sgzn.sgpay.service.tcp.SgTcpProtocolHead;
import com.sgzn.sgpay.service.tcp.util.SgTcpUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 清奖池 服务请求类
 * @author huangsenguang
 * @version Id: TcpClearRewardPoolRequest.java, v 0.1 2018/7/23 22:22 huangsenguang Exp $$
 */
@Data
@Slf4j
public class TcpClearRewardPoolRequest extends TcpCommonRequest{
    /**
     * 长度
     */
    private String length="03";

    /**
     * 索引
     */
    private String index="01";

    /**
     * 命令
     */
    private String cmd="1C";

    @Override
    public String toString(){
        //根据协议规范重载toString方法
        return beginCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                serialCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                deviceId + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                commandReq + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                head + length + index + cmd +
                getAllCheck(length + index + cmd) + end + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                checkSumCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                endCode;
    }

    /**
     * 获取校验码
     * @param needToCheck
     * @return
     */
    private String getAllCheck(String needToCheck) {
        this.setCheck(SgTcpUtil.getToCheck(needToCheck));
        return this.check;
    }


    public static void main(String[] args){
        TcpClearRewardPoolRequest tcpRequest = new TcpClearRewardPoolRequest();
        tcpRequest.setDeviceId("10001");
        log.info(tcpRequest.toString());
    }
}

